package zh.dummy.netty.client.util;

import java.util.HashMap;
import java.util.Map;

import zh.dummy.netty.core.protocol.Header;
import zh.dummy.netty.core.protocol.MessageType;
import zh.dummy.netty.core.protocol.NettyMessage;

public class NettyMessageBuilder {
	
	private final static NettyMessage heartBeat;
	
	static{
		NettyMessage message = new NettyMessage();
		Header header = new Header();
		header.setType(MessageType.HEARTBEAT_REQ.value());
		message.setHeader(header);
		heartBeat = message;
	}
	
	public static NettyMessage buildWorkflowMessage(Map<String, Object> message) {
		Header header = new Header();
		header.setType(MessageType.WORK_FLOW.getValue());
		if(NettyUtil.getClientId() != null){
			Map<String,Object> attchment = new HashMap<String,Object>();
			attchment.put("id", NettyUtil.getClientId());
			header.setAttchment(attchment);
		}
		return new NettyMessage(header,message);
	}
	
	public static NettyMessage buildAuthReq(){
		NettyMessage message = new NettyMessage();
		Header header = new Header();
		header.setType(MessageType.LOGIN_REQ.value());
		if(NettyUtil.getClientId() != null){
			Map<String,Object> attchment = new HashMap<String,Object>();
			attchment.put("id", NettyUtil.getClientId());
			header.setAttchment(attchment);
		}
		message.setHeader(header);
		return message;
	}
	
	public static NettyMessage buildHeatBeatReq(){
		return heartBeat;
	}
}
